package aip.assignment2.webservice.entity;

import java.math.BigDecimal;

/**
 *
 * @author Stone
 */
public class Purchase
{
	private String Number;
	private String Surname;
	private int productCount;
	private String status;
	private BigDecimal price;
	/**
	 * @return the Number
	 */
	public String getNumber()
	{
		return Number;
	}
	/**
	 * @param Number the Number to set
	 */
	public void setNumber(String Number)
	{
		this.Number = Number;
	}
	/**
	 * @return the Surname
	 */
	public String getSurname()
	{
		return Surname;
	}
	/**
	 * @param Surname the Surname to set
	 */
	public void setSurname(String Surname)
	{
		this.Surname = Surname;
	}
	/**
	 * @return the productCount
	 */
	public int getProductCount()
	{
		return productCount;
	}
	/**
	 * @param productCount the productCount to set
	 */
	public void setProductCount(int productCount)
	{
		this.productCount = productCount;
	}
	/**
	 * @return the status
	 */
	public String getStatus()
	{
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(String status)
	{
		this.status = status;
	}
	/**
	 * @return the price
	 */
	public BigDecimal getPrice()
	{
		return price;
	}
	/**
	 * @param price the price to set
	 */
	public void setPrice(BigDecimal price)
	{
		this.price = price;
	}
	/**
	 * The method creates a web service entity from JPA entity.
	 * @param purchase the JPA entity.
	 * @return the result web service entity.
	 */
	public static Purchase createFromJpaEntity(aip.assignment2.persistence.entity.Purchase purchase)
	{
		if (purchase == null)
		{
			return null;
		}
		Purchase result = new Purchase();
		result.setNumber(purchase.getNumber());
		result.setSurname(purchase.getCustomer().getName().getSurname());
		result.setProductCount(purchase.getProducts().size());
		result.setPrice(purchase.getTotal());
		result.setStatus(purchase.getStatus());
		return result;
	}
}
